﻿Imports System.Data.SqlClient
Public Class DanhSachKetQua

    Private _p1 As Object

    Sub New(ByVal p1 As Object)
        ' TODO: Complete member initialization 
        _p1 = p1
    End Sub

    Private Sub btnThem_Click(sender As System.Object, e As System.EventArgs) Handles btnThem.Click
        Dim frm As ThemKetQua = New ThemKetQua(SinhVien_ID)
        Me.Close()
        frm.Show()
    End Sub

    Private Sub btnSua_Click(sender As System.Object, e As System.EventArgs) Handles btnSua.Click
        Dim LanThi As Integer
        Dim MonHoc_ID As String
        Dim TenMonHoc As String
        Dim row As Integer
        row = Me.listView1.SelectedItems(0).Index
        LanThi = Convert.ToInt16(Me.listView1.Items(row).SubItems(2).Text)
        TenMonHoc = Me.listView1.Items(row).SubItems(0).Text
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = KetNoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT MonHoc_ID FROM MonHoc WHERE TenMonHoc='" + TenMonHoc + "' "
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        MonHoc_ID = td.Rows(0)(0).ToString()
        con.Close()
        Me.Close()
        Dim frm As SuaKetQua = New SuaKetQua(SinhVien_ID, MonHoc_ID, LanThi)
        frm.Show()
    End Sub

    Private Sub btnXoa_Click(sender As System.Object, e As System.EventArgs) Handles btnXoa.Click
        Dim LanThi As Integer
        Dim MonHoc_ID As String
        Dim TenMonHoc As String
        Dim row As Integer
        row = Me.listView1.SelectedItems(0).Index
        LanThi = Convert.ToInt16(Me.listView1.Items(row).SubItems(2).Text)
        TenMonHoc = Me.listView1.Items(row).SubItems(0).Text
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = KetNoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT MonHoc_ID FROM MonHoc WHERE TenMonHoc='" + TenMonHoc + "' "
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)
        MonHoc_ID = td.Rows(0)(0).ToString()
        cmd.CommandText = "DELETE FROM KetQua WHERE ID_SinhVien='" + SinhVien_ID + "' AND ID_MonHoc='" + MonHoc_ID + "' AND LanThi=" + LanThi + " "
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN XOÁ KẾT QUẢ KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
        End If

        cmd.ExecuteNonQuery()
        con.Close()
        MessageBox.Show("XÓA THÀNH CÔNG", "THÔNG BÁO")
        Me.Close()
        ' Dim frm As KetQuaHocTap = New KetQuaHocTap(SinhVien_ID)
        ' frm.Show()
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Function SinhVien_ID() As String
        Throw New NotImplementedException
    End Function

End Class